﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using NUnit.Framework;
using ECCIT;
using OgilvyOne.UKNow.Model;
using OgilvyOne.UKNow.IDAL;
using OgilvyOne.UKNow.DALFactory;

namespace OgilvyOne.UKNow.DAL.Test
{
    [TestFixture]
    [Category("")]
    public class EventsVideoDALTest
    {
        private EventsVideoModel CreateNewModel()
        {
            EventsVideoModel model = new EventsVideoModel();
            model.ID = null;
            model.LanguageID = 1033;
            model.Description = "DESC";
            model.EventsID = 1;
            model.Extension = ".flv";
            model.ImagePath = "path";
            model.InsertedTime = DateTime.Now;
            model.IsRecommendation = false;
            model.Name = "name";
            model.Order = 1;
            model.Path = "video path";
            model.State = 1;
            model.Tag = "Tag";
            model.Type = 0;
            model.UpdatedTime = DateTime.Now;

            return model;
        }

        [Test]
        public void TestSaveInsert()
        {
            EventsVideoModel model = CreateNewModel();
            IDALEventsVideo dal = EventsVideoDALFactory.Create(1033);
            try
            {
                ResultInfo result = dal.Save(model);
                Assert.AreEqual(true, result.Result);
                Assert.AreNotEqual(null, result.ReturnObject);
                Assert.AreNotEqual(0, ((EventsVideoModel)result.ReturnObject).ID);
            }
            catch (Exception ex)
            {
                Assert.Fail("Test: TestSaveInsert failed with exception: " + ex.Message);
            }
        }

        [Test]
        public void TestSaveUpdate()
        {
            EventsVideoModel model = CreateNewModel();
            IDALEventsVideo dal = EventsVideoDALFactory.Create(1033);
            try
            {
                ResultInfo result = dal.Save(model);
                Assert.AreEqual(true, result.Result);

                model.UpdatedTime = DateTime.Now;
                result = dal.Save(model);
                Assert.AreEqual(true, result.Result);
            }
            catch (Exception ex)
            {
                Assert.Fail("Test: TestSaveUpdate failed with exception: " + ex.Message);
            }
        }

        [Test]
        public void TestGetEventsVideoModelByID()
        {
            EventsVideoModel model = CreateNewModel();
            IDALEventsVideo dal = EventsVideoDALFactory.Create(1033);
            try
            {
                ResultInfo result = dal.Save(model);
                Assert.AreEqual(true, result.Result);

                EventsVideoModel retrievedModel = dal.GetEventsVideoModelByID(model.ID);
                Assert.AreNotEqual(null, retrievedModel);
                Assert.AreEqual(model.ID, retrievedModel.ID);
                Assert.AreEqual(model.Name, retrievedModel.Name);
                Assert.AreEqual(model.InsertedTime.ToString("yyyy-MM-dd hh:mm:ss"), retrievedModel.InsertedTime.ToString("yyyy-MM-dd hh:mm:ss"));
                Assert.AreEqual(model.Order, retrievedModel.Order);
            }
            catch (Exception ex)
            {
                Assert.Fail("Test: TestGetEventsVideoModelByID failed with exception: " + ex.Message);
            }
        }

        [Test]
        public void TestDelete()
        {
            EventsVideoModel model = CreateNewModel();
            IDALEventsVideo dal = EventsVideoDALFactory.Create(1033);
            try
            {
                ResultInfo result = dal.Save(model);
                Assert.AreEqual(true, result.Result);

                IList<int?> idList = new List<int?>();
                idList.Add(model.ID);
                result = dal.Delete(idList);
                Assert.AreEqual(true, result.Result);
            }
            catch (Exception ex)
            {
                Assert.Fail("Test: TestDelete failed with exception: " + ex.Message);
                Console.Write(ex.Message);
            }
        }
    }
}
